package com.jackrain.nea.omslocal.task;/**
 * Created by Administrator on 2017/3/12.
 */


import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.omslocal.service.LogisticSendAgainService;
import com.jackrain.nea.omslocal.service.LogisticsSendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Description: 自动任务,订单发货状态回传,发送同步状态消息
 * Created with IntelliJ IDEA.
 * User: cs
 * Date: 2017/12/12
 * Time: 12:44
 */
@Component
@Slf4j
public class AutoLogistcSend {

    @Autowired
    private LogisticsSendService logisticsSendService;
    @Autowired
    private LogisticSendAgainService logisticSendAgainService;
    @Autowired
    private PropertiesConf pconf;

    public void getScheduledExecutorA() {

        log.info("AutoMotThreads LogistcSend started !!!");
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    logisticsSendService.logisticsStart();
                } catch (Exception e) {
                    e.printStackTrace();
                    // 执行任务错误,将日志记录
                }
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 2, pconf.getPropertyInt("ons.logtictime"), TimeUnit.SECONDS);
    }

    public void getScheduledExecutorB() {

        log.info("AutoMotThreads LogistcSendAgain started !!!");
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    logisticSendAgainService.logisticsAgainStart();
                } catch (Exception e) {
                    e.printStackTrace();
                    // 执行任务错误,将日志记录
                }
            }
        };

        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 2, pconf.getPropertyInt("ons.logticagaintime"), TimeUnit.MINUTES);
    }


}
